package com.maserb.monitor.web.jw_our;


import com.maserb.monitor.common.AjaxResult;
import com.maserb.monitor.common.AjaxUtils;
import com.maserb.monitor.common.Func_T;
import com.maserb.monitor.entity.JwOrgEntity;
import com.maserb.monitor.entity.jwOur.JwOurEntity;
import com.maserb.monitor.entity.jwOur.JwOurLeaderEntity;
import com.maserb.monitor.service.jwEducation.JwOrgService;
import com.maserb.monitor.service.jwOur.JwOurLeaderService;
import com.maserb.monitor.service.jwOur.JwOurService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

//关于我们手机端
@Controller
@RequestMapping("/jwOurApp")
public class JwOurAppController {
    @Autowired
    private JwOurService service;

    @Autowired
    private JwOurLeaderService leaderService;

    @Autowired
    private JwOrgService orgService;

    //根据类型获取相对应的模板（1,单位简介、2,主要职能、3,信访举报须知）
    @ApiOperation(value="获取相对应的模板", notes="根据类型获取相对应的模板（1,单位简介、2,主要职能、3,信访举报须知）")
    @ApiImplicitParam(name = "type", value = "模板类型", required = true, dataType = "String", paramType = "path")
    @RequestMapping("/viewOur")
    public ModelAndView viewOur(String type){
        ModelAndView result = new ModelAndView();
        List<JwOurEntity> list = service.findByType(type);
        JwOurEntity entity = new JwOurEntity();
        if(list.size()>0){
            entity = list.get(0);
        }
        result.setViewName("jw_our/our_view");
        result.addObject("entity", entity);
        return  result;
    }

    // 获取领导班子
    @RequestMapping("/ourLeader")
    @ResponseBody
    public AjaxResult<List<JwOurLeaderEntity>> ourLeader() {
        return AjaxUtils.process(new Func_T<List<JwOurLeaderEntity>>() {
            @Override
            public List<JwOurLeaderEntity> invoke() throws Exception {
                List<JwOurLeaderEntity> list = leaderService.findAll();
                return list;
            }
        });
    }

    // 获取机构设置
    @RequestMapping("/orgOur")
    @ResponseBody
    public AjaxResult<List<JwOrgEntity>> orgOur() {
        return AjaxUtils.process(new Func_T<List<JwOrgEntity>>() {
            @Override
            public List<JwOrgEntity> invoke() throws Exception {
                String type = "2";//机构类型
                List<JwOrgEntity> list = orgService.findByType(type);
                return list;
            }
        });
    }

}
